<html>
	{% include "../common_head.html" %}
	<body>
	{% include "../common_menus.html" %}
		<div id="content">
		
		<div id="rakontu_form_style" class="rakontu_form">
		<form action="/{{dir_visit}}/{{url_relate}}
		{% if entry %}
			?{{entry.urlQuery}}
		{% else %}
			?{{rakontu.urlQuery}}
		{% endif %}
		{% if type %}&{{url_query_type}}={{type}}{% endif %}
		{% if bookmark %}&{{url_query_bookmark}}={{bookmark}}{% endif %}
		" method="post" enctype="multipart/form-data">
		
			{% if changes_saved %}
				<div class="message">{{template_changes_saved}}</div>
			{% endif %}
		
		<h3>{{template_entries_related_to}} {{entry.linkString}}</h3>
		{% if related_links %}
			<fieldset>
	      	<table border="0" cellpadding="4" cellspacing="0">
	      	<tr>
	      		<th>{{template_incoming_or_outgoing}}?</th>
	      		<th>{{template_name}},<br/>{{template_type}},<br/>{{template_contributed_by}}</th>
	      		<th>{{template_first_part_of_text}}</th>
	      		<th>{{template_link_comment}}</th>
	      		<th width="80">{{template_remove}}?</th>
	      		</tr>
	      		{% for link in related_links %}
	  				<tr>
	  				<td>
	  				{% ifequal entry.key link.itemTo.key %}
	  					{{template_incoming}}
	  				{% else %}
	  					{{template_outgoing}}
	  				{% endifequal %}
	  				</td>
	  				<td>
		  				{% ifequal entry.key link.itemTo.key %}
		  					<p>{{link.itemFrom.linkString}}</a></p>
		  					<p>{{link.itemFrom.typeForDisplay|capfirst}}</p>
		  				{% else %}
		  					<p>{{link.itemTo.linkString}}</p>
		  					<p>{{link.itemTo.typeForDisplay|capfirst}}</p>
		  				{% endifequal %}
		  				<p>
						{% if link.creator.active %}
							{{link.creator.linkString}}
							{% ifequal link.creator.key current_member.key %}
								 ({{template_you}})
							{% endifequal %}
						{% else %}
							{{template_the_former_member}} "{{link.creator.nickname}}"
						{% endif %}
						</p>
	  				</td>
	  				<td>{{link.itemTo.text_formatted|upTo:current_member.shortDisplayLength|orNbsp}}</td>
	  				<td><input type="text" name="linkComment|{{link.key}}" value="{{link.comment}}" size="40"/></td>
	  				<td>
	  					<input type="checkbox" name="removeLink|{{ link.key }}" value="yes" id="removeLink|{{ link.key }}"/>
						<label for="removeLink|{{ link.key }}">{{template_remove}}</label>
	  					</td>
	  				</tr>
	      		{% endfor %}
	      	</table>
	      	</fieldset>
	  {% else %}
	  	<p>{{template_entry_has_no_related_links}}</p>
      {% endif %}
      
		<h3>{{template_add_relations}}</h3>

		<p>{{template_show}}
		<select name="entry_type">
			{% for i in entry_types|makeRangeFromListLength %}
				<option value="{{entry_types|listLookup:i}}" 
				{% if entry_types|listLookup:i|equalTest:type %} 
					selected="selected" 
				{% endif %}
				>{{entry_types_plural_display|listLookup:i}}</option>
			{% endfor %}
			</select>
		<input type="submit" name="changeSelections" value="{{button_change}}" class="button_small">

		{% if entries %}
			<fieldset>
	      	<table border="0" cellpadding="4" cellspacing="0">
	      	<tr>
	      		<th>{{template_information|capitalize}}</th>
	      		<th width="100">{{template_add_link}}?</th>
	      		<th width="200">{{template_link_comment}}</th>
				</tr>
      		{% for anEntry in entries %}
      			<tr>
      			 <td>
      			 	{{anEntry.linkString}}
						{% if anEntry.attributedToMember %}
								{% if anEntry.creator.active %}
									{{anEntry.creator.linkString}}
									{% ifequal anEntry.creator.key current_member.key %}
										 ({{template_you}})
									{% endifequal %}
								{% else %}
									{{template_the_former_member}} "{{anEntry.creator.nickname}}"
								{% endif %}
						{% else %}
							{% if anEntry.character.active %}
								{{anEntry.character.linkString}}
							{% else %}
								{{template_the_former_character}} "{{anEntry.character.name}}"
							{% endif %}
						{% endif %}
	  				
	  				{{anEntry.published|timeZone:current_member.timeZoneName|date:current_member.dateFormat}}.
      			 <i>{{anEntry.text_formatted|upTo:current_member.shortDisplayLength|orNbsp}}</td>
      			 </td>
      			<td>
      			<input type="checkbox" name="addLink|{{anEntry.key}}" value="yes" id="addLink|{{anEntry.key}}"/>
				<label for="addLink|{{anEntry.key}}">{{template_add_link}}</label>
      			</td>
      			<td><input type="text" name="linkComment|{{anEntry.key}}" value="" size="40"/></td>
      			 </tr>
      		{% endfor %}
		    </table>	      	
		    </fieldset>
			<p>
			{% if previous %}
				 <a href="/{{dir_visit}}/{{url_relate}}?{{entry.urlQuery}}&{{url_query_type}}={{type}}&{{url_query_bookmark}}={{previous}}">{{template_newer}} {{template_entries|lower}}</a>
			{% endif %}	
			{% if previous and next %} ... {% endif %}
			{% if next %}
				 <a href="/{{dir_visit}}/{{url_relate}}?{{entry.urlQuery}}&{{url_query_type}}={{type}}&{{url_query_bookmark}}={{next}}">{{template_older}} {{template_entries|lower}}</a>
			{% endif %}	
		{% else %}
			<p>{{template_no_entries_of_this_type_to_relate_to}}</p>
		{% endif %}
		

		<p>
		<center>
		{% if related_links %}
			<input type="submit" name="save" value="{{button_save_changes}}" class="button">
		{% else %}
			{% if entries %}
				<input type="submit" name="save" value="{{button_save_new_relations}}" class="button">
			{% endif %}
		{% endif %}
		</center>
			
		</form>
		</div>
		
		<p>{{entry.linkString}} ({{entry.typeForDisplay}})</p>
		{% include "read_or_preview_entry.html" %}
		</div>
	{% include "../common_footer.html" %}
	</body>
</html>
